package com.inossem.warehousestorage_inossem.request.storage;

import android.content.Context;

import com.google.gson.Gson;
import com.inossem.warehousestorage_inossem.bean.storage.StorageManagePosiBean;
import com.inossem.warehousestorage_inossem.bean.storage.StorageManagePositionConfirmBean;
import com.inossem.warehousestorage_inossem.bean.storage.StorageManagePositionConfirmRequestBean;
import com.inossem.warehousestorage_inossem.constant.RequestConstant;
import com.inossem.warehousestorage_inossem.listener.GsonBeanListener;
import com.inossem.warehousestorage_inossem.listener.StringRequestListener;
import com.inossem.warehousestorage_inossem.manage.RequestManage;
import com.inossem.warehousestorage_inossem.model.StringResponse;
import com.inossem.warehousestorage_inossem.request.Request;

/**
 * Created by leij on 2017/6/12.
 */

public class StorageManagePosiRequest extends Request {
    public static String request(Context context, GsonBeanListener gsonBeanListener) {
        String tag;
        String url = RequestManage.getUrl(context, RequestConstant.URL_STORAGE_MANAGE_POSITION_GET_POSITION_LIST);
//        Dialog dialog = DialogUtils.getLoadingDialog(context, new DialogUtils.LoadingListener() {
//            @Override
//            public void onCancel() {
//                LogUtils.i("cancel");
//            }
//        }, "请稍等");
//        dialog.show();
//
//        JsonObjectRequest request = RequestManage.getHttpsGet(context, url, new StringRequestListener() {
//            @Override
//            public void onSuccess(StringResponse stringRequestResponse) {
//                Gson gson = new Gson();
//                String json = stringRequestResponse.getResponseInfo();
//                StorageManagePosiBean bean = gson.fromJson(json, StorageManagePosiBean.class);
//                excuteJsonBeanNew(context, bean, gsonBeanListener);
//                dialog.hide();
//            }
//        });
//        tag = addRequest(context, request, url);
        tag = RequestManage.getHttpsGetWithLoading(context, url, new StringRequestListener() {
            @Override
            public void onSuccess(StringResponse stringRequestResponse) {
                Gson gson = new Gson();
                StorageManagePosiBean bean = gson.fromJson(stringRequestResponse.getResponseInfo(), StorageManagePosiBean.class);
                excuteJsonBeanNew(context, bean, gsonBeanListener);
            }
        });
        return tag;
    }


    public static String submitPosi(Context context, StorageManagePositionConfirmRequestBean paramsBean, GsonBeanListener gsonBeanListener) {
        String tag;
        String url = RequestManage.getUrl(context, RequestConstant.URL_STORAGE_MANAGE_POSITION_SUBMIT);
        Gson gson = new Gson();
        String params = gson.toJson(paramsBean, paramsBean.getClass());
        tag = RequestManage.getHttpsPostWithLoading(context, url, params, new StringRequestListener() {
            @Override
            public void onSuccess(StringResponse stringRequestResponse) {
                Gson gson = new Gson();
                StorageManagePositionConfirmBean bean = gson.fromJson(stringRequestResponse.getResponseInfo(), StorageManagePositionConfirmBean.class);
                excuteJsonBeanNew(context, bean, gsonBeanListener);
            }
        });
//
//        Gson gson = new Gson();
//        String body = gson.toJson(bean);
//        Dialog dialog = DialogUtils.getLoadingDialog(context, null);
//        dialog.show();
//        JsonObjectRequest request = RequestManage.getHttpsPost(context, url, body, new StringRequestListener() {
//            @Override
//            public void onSuccess(StringResponse stringRequestResponse) {
//                Gson gson = new Gson();
//                String json = stringRequestResponse.getResponseInfo();
//                StorageManageRespBean bean = gson.fromJson(json, StorageManageRespBean.class);
//                excuteJsonBean(context, bean, bean.getCode(), bean.getMsg(), gsonBeanListener);
//                dialog.hide();
//            }
//        });
//        tag = addRequest(context, request, url);
        return tag;
    }
}
